package com.iob.coin.util.logutil;

import java.io.OutputStream;
import java.io.PrintWriter;
import java.sql.Timestamp;
import java.util.Map;

/**
 * @Author: GuoXinyuan
 * @Date: 2021/5/28
 * 简单日志工具 后续考虑替换为log4j
 */
public class Logger {

    public Logger(String className,OutputStream outputStream){
        this.printWriter = new PrintWriter(outputStream);
        this.className = className;
    }

    private final PrintWriter printWriter;

    private final String className;

    public void log(String flag,String message,Map<String,String> paramMap){
        Timestamp timestamp = new Timestamp(System.currentTimeMillis());
        printWriter.write(timestamp.toString());
        printWriter.write("  [" + className + "] " + flag + ": " + message);
        if(paramMap != null){
            printWriter.write(" ( ");
            paramMap.forEach((key,value)->{
                printWriter.write(key + ":" + value + "; ");
            });
            printWriter.write(")");
        }
        printWriter.write("\n");
        printWriter.flush();
    }

}
